package com.wnxy.mallserver.controller;

import com.wnxy.mallserver.entity.Goods;
import com.wnxy.mallserver.response.ResponseResult;
import com.wnxy.mallserver.service.GoodsService;
import com.wnxy.mallserver.vo.goods.GoodsListVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品展示页面的控制器类
 */
@Slf4j
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    //根据cid查询商品信息（部分信息）--返回商品信息集合
    @GetMapping("/findGoodsByCid/{cid}")
    public ResponseResult<List<GoodsListVo>> findGoodsBycid(@PathVariable("cid")Integer cid){
        log.debug("cid为：{}", cid);
        return new ResponseResult<>(ResponseResult.OK, goodsService.findGoodsBycid(cid));
    }

    /**点击图片，显示该商品的详细信息*/
    @GetMapping("/findById/{gid}")
    public ResponseResult<Goods> findById(@PathVariable("gid") Integer id){
        log.debug("商品id为{}",id);
        return new ResponseResult<>(ResponseResult.OK,goodsService.findById(id));

    }

}
